package com.msb.mall.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.msb.common.utils.PageUtils;
import com.msb.common.vo.CommonResult;
import com.msb.mall.core.entity.order.OrderEntity;
import com.msb.mall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 订单
 *
 * @author leixu
 * @email xuleiwolf@163.com
 * @date 2024-04-19 20:19:29
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/findAll")
    public CommonResult findAll(@RequestBody Map<String, Object> params) {
        IPage<OrderEntity> page = orderService.findAll(params);

        return CommonResult.success(page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);

        return CommonResult.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public CommonResult info(@PathVariable("id") Long id) {
        OrderEntity order = orderService.getById(id);

        return CommonResult.success(null, order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public CommonResult save(@RequestBody OrderEntity order) {
        orderService.save(order);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public CommonResult update(@RequestBody OrderEntity order) {
        orderService.updateById(order);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public CommonResult delete(@RequestBody Long[] ids) {
        orderService.removeByIds(Arrays.asList(ids));

        return CommonResult.success();
    }

}
